package com.code.petapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.code.petapp.R;
import com.code.petapp.bean.SubmitBean;

import java.util.List;

public class SubmitImgAdapter extends RecyclerView.Adapter<SubmitImgAdapter.MyViewHolder> {
    private Context context;
    private List<SubmitBean> list;
    private View inflater;


    public SubmitImgAdapter(Context context, List<SubmitBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        inflater = LayoutInflater.from(context).inflate(R.layout.submit_img_item, parent, false);
        MyViewHolder myViewHolder = new MyViewHolder(inflater);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        SubmitBean submitBean = list.get(position);
        holder.status.setText(submitBean.getStatus());
        holder.desc.setText(submitBean.getDescr());
        holder.time.setText(submitBean.getTime());
        Glide.with(context)
                .load(submitBean.getImg())
                .into(holder.img);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView status;
        TextView desc;
        TextView time;
        ImageView img;

        public MyViewHolder(View itemView) {//这个view参数就是recyclerview子项的最外层布局
            super(itemView);
            //可以通过findViewById方法获取布局中的TextView
            status =itemView.findViewById(R.id.status);
            img=itemView.findViewById(R.id.img);
            desc=itemView.findViewById(R.id.desc);
            time=itemView.findViewById(R.id.time);

        }
    }
}
